<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DBGenerator
 *
 * @author vlad
 */
class DBGenerator {
    //put your code here
    
    protected $_paths;
    public $HumanizeClassNames;
    
    public function AddPath($path, $type) {
        $this->_paths[$type] = $path;
    }
    
    public function CreateAllPaths() {
        $errs = 0;
        if (is_array($this->_paths)) {
            foreach ($this->_paths as $path) {
                if (!SCFileHelper::CreateDirectory($path)) {
                    $errs++;
                    throw new ErrorException("Unable to create path $path");
                }
            }
            if (!$errs) {return true;}
        }
        return false;
    }
    
    public function GetPath($index) {
        if (isset($this->_paths) && isset($this->_paths[$index])) {
            return $this->_paths[$index];
        }
        return NULL;
    }
     
    public function CreatePHPFile($fileName, $content) {
        $content = "<?php\n\n".$content;
        file_put_contents($fileName.".php", $content);
    }
    
    public function AddBaseSuffix($className) {
        return $className."_base";
    }
    
    public function HumanizeClassName($name) {
        if ($this->HumanizeClassNames) {
            $name = $this->HumanizeName($name);
        }
        return $name;
    }
    
    public function HumanizeName($name) {
        $retVal = "";
        $items = preg_split('/_+/', $name);
        foreach ($items as $item) {
            $retVal .= ucfirst($item);
        }
        return $retVal;
    }
    
}

?>
